package ${t.packagePath}.controller;
import ${t.packagePath}.service.${t.cfgTableName}Service;
import ${t.packagePath}.model.${t.cfgTableName};
import java.io.Serializable;
import java.util.List;
import java.util.Arrays;
import ${t.packagePath}.utils.AjaxJson;
import ${t.packagePath}.config.StpSpUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;
import java.lang.reflect.Method;
import cn.hutool.core.util.ReflectUtil;
import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.SearchResult;
import cn.zhxu.bs.util.MapUtils;
import javax.servlet.http.HttpServletRequest;
import io.swagger.annotations.ApiOperation;
import ${t.packagePath}.service.${t.mkNameBig}Service;
import ${t.packagePath}.model.${t.mkNameBig};
<#if cfg.saTokenAuthWay == 1 >import cn.dev33.satoken.stp.StpUtil;
<#else>import cn.dev33.satoken.annotation.SaCheckPermission;
</#if>


/**
 * Controller: 配置
 * @author ${cfg.author} 
 */
@RestController
@AllArgsConstructor(onConstructor_ = {@Autowired})
public class ${t.cfgTableName}Controller {

	${t.cfgTableName}Service ${t.cfgTableName?uncap_first}Service;
	BeanSearcher searcher;

	/**
     * 返回指定【cfgName】配置信息
     */
    @RequestMapping("/SpCfg/getCfg")
    @SaCheckPermission(type= Stp${t.userTableName}Util.TYPE,value=${t.cfgTableName}.PERMISSION_CODE)
    public AjaxJson getCfg(String cfgName) {
		${t.cfgTableName} one = ${t.cfgTableName?uncap_first}Service.lambdaQuery().eq(${t.cfgTableName}::getCfgName, cfgName).one();
        if (one == null) {
            return AjaxJson.getError("无此配置信息：" + cfgName);
        }
        return AjaxJson.getSuccessData(one.getCfgName());
    }



	/**
     * 修改指定【cfgName】配置信息
     */
    @RequestMapping("/SpCfg/updateCfg")
    @SaCheckPermission(type= Stp${t.userTableName}Util.TYPE,value=${t.cfgTableName}.PERMISSION_CODE)
    public AjaxJson updateCfg(String cfgName, String cfgValue) {
		${t.cfgTableName} one = ${t.cfgTableName?uncap_first}Service.lambdaQuery().eq(${t.cfgTableName}::getCfgName, cfgName).one();
        if (one == null) {
            return AjaxJson.getError("无此配置信息：" + cfgName);
        }
        one.setCfgValue(cfgValue);
        boolean b = ${t.cfgTableName?uncap_first}Service.updateById(one);
        return AjaxJson.getByBoolean(b);
    }


	/**
     * 返回应用配置信息 （对公开放的）
     */
    @RequestMapping("/SpCfg/appCfg")
    public AjaxJson appCfg() {
		${t.cfgTableName} one = ${t.cfgTableName?uncap_first}Service.lambdaQuery().eq(${t.cfgTableName}::getCfgName, "app_cfg").one();
        if (one == null) {
            return AjaxJson.getSuccessData(null);
        }
        return AjaxJson.getSuccessData(one.getCfgValue());
    }
}
